//
//  PopUpPresentationController.swift
//  WeiBoSwift
//
//  Created by Jacky Sun on 16/4/22.
//  Copyright © 2016年 syf. All rights reserved.
//

import UIKit

class PopUpPresentationController: UIPresentationController {

    var popViewFrame = CGRectZero
    
    
    
    /**
     初始化方法，用于创建负责转场动画的对象
     
     - parameter presentedViewController:  被展示的控制器
     - parameter presentingViewController: 发起的控制器，xcode6是nil，xcode7是野
     
     - returns: <#return value description#>
     */
   override init(presentedViewController: UIViewController, presentingViewController: UIViewController) {
        super.init(presentedViewController: presentedViewController, presentingViewController: presentingViewController)
    }
    
    
    /**
     布局转场子视图
     */
    override func containerViewWillLayoutSubviews() {
        // 1.修改弹出视图的大小
        //        containerView; // 容器视图
        //        presentedView() // 被展现的视图
        
       let tabView = presentedView()
        tabView!.frame = popViewFrame
        containerView?.addSubview(coverView)
        containerView!.bringSubviewToFront(tabView!)
        
       // containerView?.insertSubview(coverView, atIndex: 0)
    }
    
    
    
    
    private lazy var coverView : UIView = {
        let view = UIView()
        view.frame = UIScreen.mainScreen().bounds
        view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.2)
        let tap = UITapGestureRecognizer(target: self, action: #selector(PopUpPresentationController.backGroundClick))
        view.addGestureRecognizer(tap)
        return view;
    }()
    
    
    func backGroundClick() {
        presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    }
}


